<?php
/**
 * @package Freshine
 * @since Freshine 2.1.0
 */

/* Theme Options */
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
$themename = $theme_data['Name'];
$shortname = "f9";

/*-----------------------------------------------------------------------------------*/
/*	Add Theme Options Menu
/*-----------------------------------------------------------------------------------*/
// This function adds the top-level menu
function f9_add_admin_menus() {
    global $menu, $themename;
	$menu['58.995'] = array( '', 'edit_themes', 'separator-f9', '', 'wp-menu-separator' );
	add_menu_page($themename, $themename, 'edit_themes', 'theme-options' , 'f9_admin', get_bloginfo('template_directory').'/functions/images/icon_yoarts.png', '58.996');
	
}
add_action('admin_menu', 'f9_add_admin_menus');

// // Add "Theme Options" submenu
add_action('admin_menu', 'f9_add_admin_submenus');
function f9_add_admin_submenus() {
	// Add "Theme Options" submenu
	add_submenu_page('theme-options', 'Theme Options', 'Theme Options' , 'edit_themes', 'theme-options', 'f9_admin');
}

/*-----------------------------------------------------------------------------------*/
/*	Options Values
/*-----------------------------------------------------------------------------------*/
$options = array();

/* General */
$options[] = array(	"name" => "General",
					"id" => $shortname."_group_general",
					"type" => "group-open");

$options[] = array(	"name" => "Logo Type",
					"id" => $shortname."_logo_type",
					"std" => 0,
					"options" => array("Image (Put your link below)","Wordpress Title"),
					"type" => "select");
	
$options[] = array(	"name" => "Logo URL",
					"desc" => "",
					"id" => $shortname."_logo_url",
					"std" => '',
					"type" => "text");
					
$options[] = array(	"name" => "Logo Image",
					"desc" => "",
					"id" => $shortname."_logo_image",
					"std" => '',
					"type" => "upload");
	
$options[] = array(	"name" => "Logo Width",
					"desc" => "px",
					"id" => $shortname."_logo_width",
					"std" => '394',
					"type" => "text");
	
$options[] = array(	"name" => "Logo Height",
					"desc" => "px",
					"std" => '56',
					"id" => $shortname."_logo_height",
					"type" => "text");
					
$options[] = array(	"name" => "Favicon URL",
					"desc" => "",
					"id" => $shortname."_favicon_url",
					"std" => '',
					"type" => "text");
					
$options[] = array(	"name" => "Main Menu",
					"desc" => "Disable the Main Menu?",
					"id" => $shortname."_main_menu",
					"type" => "checkbox",
					"std" => "true");
					
$options[] = array(	"name" => "Custom style",
					"id" => $shortname."_custom_style",
					"desc" => "Write your custom CSS here, It will auto include in the bottom of theme's CSS",
					"type" => "textarea",
					"std" => "");	
					
$options[] = array( "type" => "group-close");

/* Layout */
$options[] = array(	"name" => "Layout",
					"id" => $shortname."_group_layout",
					"type" => "group-open");
					
$options[] = array(	"name" => "Choose main layout",
					"id" => $shortname."_site_layout",
					"std" => "2cl",
					"options" => array("1c", "2cl", "2cr", "3cl", "3cm", "3cr"),
					"type" => "layout");
	
$options[] = array(	"desc" => "Disable Sidebar Header Top",
					"id" => $shortname."_sidebar_header_top",
					"type" => "checkbox",
					"std" => "true");
	
$options[] = array(	"desc" => "Disable Sidebar Header?",
					"id" => $shortname."_sidebar_header",
					"type" => "checkbox",
					"std" => "true");
	
$options[] = array(	"desc" => "Disable Sidebar Top?",
					"id" => $shortname."_sidebar_top",
					"type" => "checkbox",
					"std" => "true");
	
$options[] = array(	"desc" => "Disable Sidebar Bottom?",
					"id" => $shortname."_sidebar_bottom",
					"type" => "checkbox",
					"std" => "true");
	
$options[] = array(	"desc" => "Disable Sidebar Content Top?",
					"id" => $shortname."_sidebar_content_top",
					"type" => "checkbox",
					"std" => "true");
	
$options[] = array(	"desc" => "Disable Sidebar Content Bottom?",
					"id" => $shortname."_sidebar_content_bottom",
					"type" => "checkbox",
					"std" => "true");
					
$options[] = array( "type" => "group-close");

/* Style */
$options[] = array(	"name" => "Style",
					"id" => $shortname."_group_style",
					"type" => "group-open");
					
$options[] = array(	"desc" => "Hide style control panel in front-page?",
					"id" => $shortname."_hide_style_panel",
					"type" => "checkbox",
					"name" => "Style control panel",
					"std" => "true");
					
$options[] = array(	"name" => "Site style",
					"id" => $shortname."_site_style",
					"std" => "",
					"type" => "select_style");
					
$options[] = array(	"name" => "General font family",
					"id" => $shortname."_font_general",
					"std" => '',
					"type" => "select_font");
					
$options[] = array(	"name" => "Apply for tags",
					"id" => $shortname."_font_general_apply",
					"std" => 'body',
					"type" => "text");
					
$options[] = array(	"name" => "Heading font family",
					"id" => $shortname."_font_heading",
					"std" => '',
					"type" => "select_font");
					
$options[] = array(	"name" => "Apply for tags",
					"id" => $shortname."_font_heading_apply",
					"std" => 'h1, h2, h3, h4, h5, h6',
					"type" => "text");
					
$options[] = array( "type" => "group-close");

//Home Setting
if ( current_theme_supports('f9_custom_home_query') ) {
$options[] = array(	"name" => "Home",
					"id" => $shortname."_group_home",
					"type" => "group-open");
					
$options[] = array(	"name" => "Home Settings",
					"type" => "title");
	
$options[] = array(	"desc" => "Select home category",
					"id" => $shortname."_home_category",
					"type" => "category");
					
$options[] = array( "type" => "group-close");
}

//Security Settings
$options[] = array(	"name" => "Security",
					"id" => $shortname."_group_security",
					"type" => "group-open");
					
$options[] = array(	"name" => "Security Settings",
					"type" => "title");
	
$options[] = array(	"desc" => "Hide WordPress Version in the Header Tag",
					"id" => $shortname."_hide_wp_version",
					"type" => "checkbox",
					"std" => "true");
					
$options[] = array( "type" => "group-close");

/*-----------------------------------------------------------------------------------*/
/*	Theme Options Display
/*-----------------------------------------------------------------------------------*/
add_action('admin_menu', 'f9_add_admin');
function f9_add_admin() {
    global $themename, $shortname, $options;
    if ( isset($_GET['page']) && $_GET['page'] == 'theme-options' ) {
        if ( isset($_REQUEST['action']) && 'save' == $_REQUEST['action'] ) {
                foreach ($options as $value) {
                    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
                foreach ($options as $value) {
                    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
                header("Location: admin.php?page=theme-options&saved=true");
                die;
        } else if( isset($_REQUEST['action']) && 'reset' == $_REQUEST['action'] ) {
            foreach ($options as $value) {
                delete_option( $value['id'] ); }
            	header("Location: admin.php?page=theme-options&reset=true");
            die;

        }
    }
}

function freshine_options_script() {
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$(".nav-tab-wrapper a:first").addClass("nav-tab-active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$(".nav-tab-wrapper a").click(function() {

		$(".nav-tab-wrapper a").removeClass("nav-tab-active"); //Remove any "active" class
		$(this).addClass("nav-tab-active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
	
	$(".layout-list li").click(function() {
		$("input[name=f9_site_layout]").val($(this).find("img").attr("alt"));
		$(".layout-list li").removeClass("active");
		$(this).addClass("active");
	return false;
	});
});
</script>
<style type="text/css">
.layout-list li {
	display: inline-block;
	border: 3px solid #eee;
	margin: 0 5px 0 0;
	cursor: pointer;
}

.layout-list li.active {
	border-color: #ccc;	
}

.layout-list li img {
	display: block;
}

.sidebar-positions {
	position: relative;
	margin: 5px 0 0;
}

.sidebar-positions img {
	position: absolute;
}

</style>
<?php
}
if ( isset($_GET['page']) && $_GET['page'] == 'theme-options' ) {
	add_action('admin_footer', 'freshine_options_script');
}

//Theme Options page
function f9_admin() {
    global $themename, $shortname, $options;
?>
<div class="wrap">
	<?php screen_icon('options-general'); ?>
	<h2><?php echo $themename.' Theme Options'; ?></h2>
	<h2 class="nav-tab-wrapper">
		<?php
		foreach ($options as $value) {
			if($value['type']=="group-open") {
				echo '<a href="#'.$value['id'].'" class="nav-tab">'.$value['name'].'</a>';
			}
		} ?>
	</h2>
	<?php 
		if ( isset($_REQUEST['saved']) ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' options saved.</strong></p></div>';
		if ( isset($_REQUEST['reset']) ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' options reset.</strong></p></div>';
	?>
	
	<form method="post">
		<div class="tab_container">
			<?php
			
			foreach ($options as $value) {
			switch ( $value['type'] ) {
				//Group Open
				case 'group-open': ?>
			<div id="<?php echo $value['id']; ?>" class="tab_content">
				<table class="form-table">
					<tbody>
				<?php break;
				
				//Group Close
				case 'group-close': ?>
					</tbody>
				</table>
			</div>
				<?php break;
				
				//Text field
				case 'text': ?>
				<tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
					<td><input class="regular-text" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id'] )); } else { if(isset($value['std'])) echo stripslashes($value['std']); } ?>">
					<span class="description"><?php if(isset($value['desc'])) echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php break;
		
				//Textarea
				case 'textarea': ?>
				<tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
					<td>
					<textarea name="<?php echo $value['id']; ?>" cols="100" rows="5" type="<?php echo $value['type']; ?>"><?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id'] )); } else { echo stripslashes($value['std']); } ?></textarea>
					<br /><span class="description"><?php echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php break;

				//Select
				case 'select': ?>
				<tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
					<td>
						<select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
							<?php $i=0; foreach ($value['options'] as $option) { ?>
							<option value="<?php echo $i; ?>" <?php if ( get_option( $value['id'] ) == $i) { echo ' selected="selected"'; } ?>>
								<?php echo $option; ?>
							</option>
							<?php $i++; } ?>
						</select>
						<span class="description"><?php if(isset($value['desc'])) echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php
				break;
				
				//Select style
				case 'select_style':
				if ($handle = opendir(STYLESHEETPATH.'/styles/')) {
				?>
				<tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
					<td>
						<select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
						<option value=""<?php if ( get_option( $value['id'] ) == '') { echo ' selected="selected"'; } ?>>Default</option>
<?php while (false !== ($entry = readdir($handle))) {
		if ($entry != "." && $entry != ".." && substr($entry, -3) == "css" ) { ?>
							<option value="<?php echo substr($entry, 0, -4); ?>"<?php if ( get_option( $value['id'] ) == substr($entry, 0, -4)) { echo ' selected="selected"'; } ?>><?php echo str_replace('-',' ', substr($entry, 0, -4)); ?></option>
		<?php }
	}
closedir($handle); ?>
						</select>
						<span class="description"><?php if(isset($value['desc'])) echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php
				}
				break;
				
				//Select font
				case 'select_font': ?>
				<tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
					<td>
						<select id="<?php echo $value['id']; ?>" name="<?php echo $value['id']; ?>" class="webfonts" style="width:240px;">
						</select>
						<span class="description"><?php if(isset($value['desc'])) echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php
				break;

				case 'category': ?>
				<tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label></th>
					<td>
						<?php
						if(get_option($value['id'])) {
							wp_dropdown_categories('show_option_all=All categories&name='.$value['id'].'&selected='.get_option($value['id']));
						} else {
							wp_dropdown_categories('show_option_all=All categories&name='.$value['id']);
						}
						?>
						<span class="description"><?php if(isset($value['desc'])) echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php
				break;
				
				case 'layout': ?>
				<tr valign="top">
					<th scope="row">
					Freshine sidebar positions
					<div class="sidebar-positions">
					<img src="<?php echo get_bloginfo('template_directory').'/functions/images/sidebar-positions.jpg'; ?>" alt="Sidebar" />
					</div>
					</th>
					<td>
						<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
						<input name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="hidden" value="<?php if ( get_option( $value['id'] ) != "") { echo stripslashes(get_option( $value['id'] )); } else { if(isset($value['std'])) echo stripslashes($value['std']); } ?>">
						<ul class="layout-list">
							<?php
							foreach ($value['options'] as $option) { ?>
							<li<?php if(get_option( $value['id'] ) == $option) echo' class="active"';?>><img src="<?php echo get_bloginfo('template_directory').'/functions/images/'.$option.'.png'; ?>" alt="<?php echo $option; ?>" /></li>
							<?php } ?>
						</ul>
						<span class="description"><?php if(isset($value['desc'])) echo $value['desc']; ?></span>
					</td>
				</tr>
				<?php
				break;
				
				case "checkbox": ?>
				  <tr valign="top">
					<th scope="row"><label for="<?php echo $value['id']; ?>"><?php if(isset($value['name'])) echo $value['name']; ?></label></th>
					<td><?php if(get_option($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = "";} ?>
					  <input type="checkbox" name="<?php echo $value['id']; ?>" value="true" id="<?php echo $value['id']; ?>" <?php echo $checked; ?> />
					  <span><?php echo $value['desc']; ?></span></td>
				  </tr>
				  <?php
				break;
				}
			} ?>
		</div>
		<p class="submit">
			<input name="save" type="submit" value="Save changes" class="button-primary" />
			<input type="hidden" name="action" value="save" />
		</p>
	</form>
	<form method="post">
		<p class="submit">
			<input name="reset" type="submit" value="Reset" />
			<input type="hidden" name="action" value="reset" />
		</p>
	</form>
</div>
<?php
}

/*-----------------------------------------------------------------------------------*/
/*	Check options
/*-----------------------------------------------------------------------------------*/
global $options;
foreach ($options as $value) {
	if(isset($value['id'])&&isset($value['std'])) :
		if (get_option($value['id']) === FALSE) {
			$value['id'] = $value['std'];
		} else {
			$value['id'] = get_option( $value['id'] );
		}
	endif;
}

/*-----------------------------------------------------------------------------------*/
/*	Remove WordPress Versions
/*-----------------------------------------------------------------------------------*/
if(get_option('f9_hide_wp_version') == TRUE) {
	remove_action('wp_head', 'wp_generator');
}

/*-----------------------------------------------------------------------------------*/
/*	Freshine cPanel
/*-----------------------------------------------------------------------------------*/
$theme_data = get_theme_data( get_stylesheet_directory() . '/style.css');
$theme_name = str_replace(' ', '-',$theme_data['Name']);
function freshine_cpanel() {
if(get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
	global $theme_name;
	?>
<div id="f9-cpanel">
	<a href="#" id="f9-cpanel-toggle">Cpanel</a>
	<div id="f9-cpanel-main">
		<form method="post" id="f9-cpanel-form">
		<div class="f9-cpanel-head clearfix">
            <a title="About Freshine" href="http://yoarts.com/freshine">Freshine framework</a>
        </div>
		<div class="f9-cpanel-tools clearfix">
			
			<h3>Site style</h3>
			<div class="f9-box-usertool">
<?php if ($handle = opendir(STYLESHEETPATH.'/styles/')) {
if($_REQUEST['f9-cpanel-style']) {
	$selected_style = $_REQUEST['f9-cpanel-style'];
} elseif ($_COOKIE[$theme_name.'-style']) {
	$selected_style = $_COOKIE[$theme_name.'-style'];
} elseif(get_option('f9_site_style')) {
	$selected_style = get_option('f9_site_style');
} else {
	$selected_style = "";
} ?>
				<ul class="f9-usertools-profile clearfix">
					<li class="profile">
						<input type="radio" value="default" <?php if($selected_style=="default") echo 'checked="checked" ';?>name="f9-cpanel-style" id="f9-cpanel-style">
						<label title="Default" for="user_profile">
						<span>Default</span>
						</label>
					</li>

<?php while (false !== ($entry = readdir($handle))) {
		if ($entry != "." && $entry != ".." && substr($entry, -3) == "css" ) { ?>
					<li class="profile">
						<input type="radio" value="<?php echo substr($entry, 0, -4); ?>" <?php if($selected_style==substr($entry, 0, -4)) echo 'checked="checked" ';?>name="f9-cpanel-style" class="f9-cpanel-style" id="f9-cpanel-style_<?php echo substr($entry, 0, -4); ?>">
						<label title="<?php echo substr($entry, 0, -4); ?>" for="f9-cpanel-style_<?php echo substr($entry, 0, -4); ?>">
						<span><?php echo str_replace('-',' ', substr($entry, 0, -4)); ?></span>
						</label>
					</li>
		<?php }
}
closedir($handle); ?>
				</ul>
			</div>
<?php } ?>
			<h3>General font</h3>
			<div class="f9-box-usertool">
			<select id="f9-cpanel-general-font" name="f9-cpanel-general-font" class="webfonts"></select>
			</div>
			<h3>Heading font</h3>
			<div class="f9-box-usertool">
			<select id="f9-cpanel-heading-font" name="f9-cpanel-heading-font" class="webfonts"></select>
			</div>
			
		</div>
		<div class="f9-cpanel-action clearfix">
            <input title="Apply setting" type="submit" class="f9-cpanel-apply" value="Apply" />
        </div>
		</form>
	</div>
</div>
<?php
endif;
}

function freshine_cpanel_script() { ?>
<script type="text/javascript">
$(document).ready(function() {
	//cPanel Toggle
	$("#f9-cpanel-toggle").click(function() {
		$("#f9-cpanel-main").slideToggle("normal");
		$(this).addClass('active');
	});
	var target = $(".webfonts"),
	api = 'https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyDXt6e2t_gCfhlSfY8ShpR9WpqjMsjEimU&sort=popularity',
	html = "",
	onSuccess = function(data){
		
		if ( data.kind === "webfonts#webfontList") {
			html += "<option value='default'>Default</option>";
			$.each(data.items, function(i, value) {
				html += "<option value='"+value.family+"'>"+value.family+"</option>";
			})
			target.html(html);
		}
		else {
			onError()
		}
	},
	onError = function() {
		target.html("<option value=''>Can't load Webfonts</option>")
	}
	
	$.ajax({
		url: api,
		type: "GET",
		dataType: "jsonp",
		success: onSuccess,
		error: onError
	})
});
</script>
<?php }
if(get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
	add_action('wp_footer', 'freshine_cpanel_script');
endif;
add_action('admin_footer', 'freshine_cpanel_script');

/*-----------------------------------------------------------------------------------*/
/*	Apply style settings
/*-----------------------------------------------------------------------------------*/
if(get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
	if($_REQUEST['f9-cpanel-style']&&$_REQUEST['f9-cpanel-style']<>"") :
		setcookie($theme_name.'-style', $_REQUEST['f9-cpanel-style']);
	endif;
	if($_REQUEST['f9-cpanel-general-font']&&$_REQUEST['f9-cpanel-general-font']<>"") :
		setcookie($theme_name.'-general-font', $_REQUEST['f9-cpanel-general-font']);
	endif;
	if($_REQUEST['f9-cpanel-heading-font']&&$_REQUEST['f9-cpanel-heading-font']<>"") :
		setcookie($theme_name.'-heading-font', $_REQUEST['f9-cpanel-heading-font']);
	endif;
endif;

function freshine_cpanel_apply() {
	global $theme_name; ?>
	<?php
	//Site style
	if($_REQUEST['f9-cpanel-style']<>"default") {
		if ($_REQUEST['f9-cpanel-style']&&$_REQUEST['f9-cpanel-style']<>""&&get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
			wp_register_style('f9_style_choosed', get_bloginfo('stylesheet_directory').'/styles/'.$_REQUEST['f9-cpanel-style'].'.css');
		elseif (isset($_COOKIE[$theme_name.'-style'])&&$_COOKIE[$theme_name.'-style']<>""&&get_option('f9_hide_style_panel')==FALSE) :
			wp_register_style('f9_style_choosed', get_bloginfo('stylesheet_directory').'/styles/'.$_COOKIE[$theme_name.'-style'].'.css');
		elseif(get_option('f9_site_style')<>'') :
			wp_register_style('f9_style_choosed', get_bloginfo('stylesheet_directory').'/styles/'.get_option('f9_site_style').'.css');
		endif;
		wp_enqueue_style( 'f9_style_choosed');
	}
	
	
	//Heading font
	if ($_REQUEST['f9-cpanel-heading-font']&&$_REQUEST['f9-cpanel-heading-font']<>""&&get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
		$heading_font_family = $_REQUEST['f9-cpanel-heading-font'];
	elseif (isset($_COOKIE[$theme_name.'-heading-font'])&&$_COOKIE[$theme_name.'-heading-font']<>""&&get_option('f9_hide_style_panel')==FALSE) :
		$heading_font_family = $_COOKIE[$theme_name.'-heading-font'];
	elseif(get_option('f9_font_heading')<>'') :
		$heading_font_family = get_option('f9_font_heading');
	endif;
	
	//General font
	if ($_REQUEST['f9-cpanel-general-font']&&$_REQUEST['f9-cpanel-general-font']<>""&&get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
		$general_font_family = $_REQUEST['f9-cpanel-general-font'];
	elseif (isset($_COOKIE[$theme_name.'-general-font'])&&$_COOKIE[$theme_name.'-general-font']<>""&&get_option('f9_hide_style_panel')&&get_option('f9_hide_style_panel')==FALSE) :
		$general_font_family = $_COOKIE[$theme_name.'-general-font'];
	elseif(get_option('f9_font_general')<>'') :
		$general_font_family = get_option('f9_font_general');
	endif;
	
	if($general_font_family<>"default") :
	echo '<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family='.str_replace(" ",'+',$general_font_family).'">';
	endif;
	if($heading_font_family<>"default") :
		echo '<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family='.str_replace(" ",'+',$heading_font_family).'">';	endif;
	if($general_font_family<>"default"||$heading_font_family<>"default") :
		echo '<style type="text/css">';
		if($general_font_family<>"default") :
			echo get_option('f9_font_general_apply').' {font-family: '.$general_font_family.';}';
		endif;
		if($heading_font_family<>"default") :
			echo get_option('f9_font_heading_apply').' {font-family: '.$heading_font_family.';}';
		endif;
		echo '</style>';
	endif;
}
add_action('wp_head', 'freshine_cpanel_apply');